Skip to content

HHH-19365 GaussDB Dialect Support #10199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

liubao68
Copy link

@liubao68 liubao68 commented May 22, 2025

As discussed, move new Dialect Support to community.

see old PR to core #10093


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-19365

@liubao68 liubao68 changed the title [HHH-19365]GaussDB Dialect Support HHH-19365 GaussDB Dialect Support May 22, 2025
@liubao68
Copy link
Author

Everything is ready for review

@liubao68
Copy link
Author

Build and test:

./docker_db.sh gaussdb
./gradlew build -Pdb=gaussdb -DdbHost=localhost:8000

BUILD SUCCESSFUL in 25m 56s

@quaff
Copy link
Contributor

quaff commented May 22, 2025

IMHO, the GaussDB Dialect should extends PostgreSQL Dialect to reuse code as possible, not to duplicate all related sources.

@liubao68
Copy link
Author

liubao68 commented May 22, 2025

IMHO, the GaussDB Dialect should extends PostgreSQL Dialect to reuse code as possible, not to duplicate all related sources.

Actually, GaussDB has many different features than PostgreSQL and now the tested mode is Oracle compatibility . In future, GaussDB will not compatible with PostgreSQL but with OpenGauss. And a separation of code may help us testing and add new features.

Your suggestion is quite good for less code duplication. But there are some potential risks. For example, a contributor modified PostgreSQL related code will influence GaussDB, however, Hibernate community is not respnosible for fixing problems in community dialect.

Copy link
Member

@beikov beikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, GaussDB has many different features than PostgreSQL and now the tested mode is Oracle compatibility . In future, GaussDB will not compatible with PostgreSQL but with OpenGauss. And a separation of code may help us testing and add new features.

Your suggestion is quite good for less code duplication. But there are some potential risks. For example, a contributor modified PostgreSQL related code will influence GaussDB, however, Hibernate community is not respnosible for fixing problems in community dialect.

This amount of code copying is IMO neither sensible nor useful. Please reuse as much of the code as possible and start copying + adapting once you GaussDB becomes non-compatible to PostgreSQL.

@liubao68
Copy link
Author

liubao68 commented Jul 1, 2025

Actually, GaussDB has many different features than PostgreSQL and now the tested mode is Oracle compatibility . In future, GaussDB will not compatible with PostgreSQL but with OpenGauss. And a separation of code may help us testing and add new features.

Your suggestion is quite good for less code duplication. But there are some potential risks. For example, a contributor modified PostgreSQL related code will influence GaussDB, however, Hibernate community is not respnosible for fixing problems in community dialect.

This amount of code copying is IMO neither sensible nor useful. Please reuse as much of the code as possible and start copying + adapting once you GaussDB becomes non-compatible to PostgreSQL.

You have mentioned two options: 1. GaussDB reuse code of PostgreSQL and 2. Not testging GaussDB in CI. If I follow option 1, and I think I can't follow option 2, because It's hard for me to know when to test the code(Maybe every minor release of hibernate). If I follow optioin 2, I can't follow option 1, a seperation of code can avoid side effects from modifications to PostgreSQL.

@gavinking
Copy link
Member

Your suggestion is quite good for less code duplication. But there are some potential risks. For example, a contributor modified PostgreSQL related code will influence GaussDB

@liubao68 I think you're thinking that copying a lot of code will make your code more resistant to breakage when the rest of HIbernate changes, but in fact it seems to me much more likely that the exact opposite is true. The less copied code you are responsible for maintaining, the more you will benefit from fixes everyone else makes.

@liubao68
Copy link
Author

liubao68 commented Jul 1, 2025

Your suggestion is quite good for less code duplication. But there are some potential risks. For example, a contributor modified PostgreSQL related code will influence GaussDB

@liubao68 I think you're thinking that copying a lot of code will make your code more resistant to breakage when the rest of HIbernate changes, but in fact it seems to me much more likely that the exact opposite is true. The less copied code you are responsible for maintaining, the more you will benefit from fixes everyone else makes.

Thank you for your suggestion. I will take more time to analyse the code copied from PostgreSQL implementation and check their differences and make a final decision. Actuall many classes have some differences that I can't extend from PostgreSQL classes. I just don't want to dependend on PostgreSQL implementations, and I will reuse hibernate codes as much as possible.

And in my future plan, I will add M and other compatibility adapter for hibernate. Sorry I can't do it at once now, because I also dpendend on some testing infrastructure not available now.

@beikov
Copy link
Member

beikov commented Jul 1, 2025

You have mentioned two options: 1. GaussDB reuse code of PostgreSQL and 2. Not testging GaussDB in CI. If I follow option 1, and I think I can't follow option 2, because It's hard for me to know when to test the code(Maybe every minor release of hibernate). If I follow optioin 2, I can't follow option 1, a seperation of code can avoid side effects from modifications to PostgreSQL.

You can e.g. sync your fork automatically and add a custom workflow file to the fork for testing GaussDB on GitHub Actions of your fork. That way, you get the latest changes built and tested automatically and if you subscribe to your fork, you will receive emails about workflow failures so you can act on that.

@liubao68
Copy link
Author

liubao68 commented Jul 1, 2025

About code

You have mentioned two options: 1. GaussDB reuse code of PostgreSQL and 2. Not testging GaussDB in CI. If I follow option 1, and I think I can't follow option 2, because It's hard for me to know when to test the code(Maybe every minor release of hibernate). If I follow optioin 2, I can't follow option 1, a seperation of code can avoid side effects from modifications to PostgreSQL.

You can e.g. sync your fork automatically and add a custom workflow file to the fork for testing GaussDB on GitHub Actions of your fork. That way, you get the latest changes built and tested automatically and if you subscribe to your fork, you will receive emails about workflow failures so you can act on that.

Thanks. I will try it.

@liubao68
Copy link
Author

liubao68 commented Jul 1, 2025

There is one major problem left about code duplication, I'd like give more explaination about it. Because we developed a new Dialect, for best practises, we reused PostgreSQL's code and structures to help us do it easier.

And I compared files newly added which reused from PostgreSQL, almost one harf is different from PostgreSQL and cann't inheritant in class level like GaussDBCallableStatementSupport extends PostgreSQLCallableStatementSupport .

GaussDBUUIDJdbcType PostgreSQLUUIDJdbcType same
GaussDBArrayJdbcType PostgreSQLArrayJdbcType same
GaussDBArrayJdbcTypeConstructor PostgreSQLArrayJdbcTypeConstructor same
GaussDBCallableStatementSupport PostgreSQLCallableStatementSupport diff
GaussDBCastingInetJdbcType PostgreSQLCastingInetJdbcType same
GaussDBCastingIntervalSecondJdbcType PostgreSQLCastingIntervalSecondJdbcType diff
GaussDBCastingJsonArrayJdbcType PostgreSQLCastingJsonArrayJdbcType same
GaussDBCastingJsonArrayJdbcTypeConstructor PostgreSQLCastingJsonArrayJdbcTypeConstructor same
GaussDBCastingJsonJdbcType PostgreSQLCastingJsonJdbcType same 
GaussDBEnumJdbcType PostgreSQLEnumJdbcType same
GaussDBOrdinalEnumJdbcType PostgreSQLOrdinalEnumJdbcType same
GaussDBSqlAstTranslator PostgreSQLSqlAstTranslator diff
GaussDBUUIDJdbcType PostgreSQLUUIDJdbcType same
GaussDBAggregateSupport PostgreSQLAggregateSupport diff
GaussDBMinMaxFunction PostgreSQLMinMaxFunction same
GaussDBTruncFunction PostgreSQLTruncFunction diff
GaussDBTruncRoundFunction PostgreSQLTruncRoundFunction same
GaussDBArrayConcatElementFunction PostgreSQLArrayConcatElementFunction diff
GaussDBArrayConcatFunction PostgreSQLArrayConcatFunction same
GaussDBArrayConstructorFunction PostgreSQLArrayConstructorFunction same
GaussDBArrayFillFunction PostgreSQLArrayFillFunction diff
GaussDBArrayPositionFunction PostgreSQLArrayPositionFunction diff
GaussDBArrayPositionsFunction PostgreSQLArrayPositionsFunction same
GaussDBArrayRemoveIndexFunction OracleArrayRemoveIndexFunction diff
GaussDBJsonObjectFunction PostgreSQLJsonObjectFunction diff
GaussDBIdentityColumnSupport PostgreSQLIdentityColumnSupport diff
GaussDBSequenceSupport PostgreSQLSequenceSupport same

Besides from these identical files, there are same other newly added files PostgreSQL do not have.

And most of all, I will give an example that's not quite appropriate. The OracleXmlArrayJdbcTypeConstructor is quite identical to the PostgreSQLArrayJdbcTypeConstructor in code. If OracleXmlArrayJdbcTypeConstructor extends from PostgreSQLArrayJdbcTypeConstructor, it would imply that Oracle has compatibility considerations with PostgreSQL, which could mislead new developers.

In its early days, GaussDB was developed from PostgreSQL, but it is no longer compatible with PostgreSQL in the present and future. I do not expect new developers to have such a misunderstanding about compatibility.

@liubao68
Copy link
Author

liubao68 commented Jul 1, 2025

I add a fored push to resolve conflicts.

@beikov
Copy link
Member

beikov commented Jul 1, 2025

Please, just try to reuse as much code as possible instead of copying code. For example, apparently you implement the same string format for structures/array like PostgreSQL since GaussDBAbstractStructuredJdbcType is more or less the same as AbstractPostgreSQLStructJdbcType and copying that code is especially not a good idea IMO, because we might have to touch the code in the future.
I would much rather have our existing types provide methods that you can override in subclasses to achieve your goals. That will make it easier for us all.

@liubao68
Copy link
Author

liubao68 commented Jul 1, 2025

Please, just try to reuse as much code as possible instead of copying code. For example, apparently you implement the same string format for structures/array like PostgreSQL since GaussDBAbstractStructuredJdbcType is more or less the same as AbstractPostgreSQLStructJdbcType and copying that code is especially not a good idea IMO, because we might have to touch the code in the future. I would much rather have our existing types provide methods that you can override in subclasses to achieve your goals. That will make it easier for us all.

Do you mean GaussDBAbstractStructuredJdbcType with AbstractPostgreSQLStructJdbcType only or other files I listed above? these two files have special reasons and I can explain and find a better solution.

@beikov
Copy link
Member

beikov commented Jul 1, 2025

End-users shouldn't interact with these types directly, so I hardly think that when you extend these types, it will imply anything. I understand your point, but you can still copy the code when you realize that it doesn't work anymore for what GaussDB needs.

@beikov
Copy link
Member

beikov commented Jul 1, 2025

To be very clear, I'm not talking about reusing such glue classes like PostgreSQLArrayJdbcTypeConstructor and OracleXmlArrayJdbcTypeConstructor that you brought up. I'm talking about copying 500+ line classes for no good reason.

@liubao68
Copy link
Author

liubao68 commented Jul 1, 2025

To be very clear, I'm not talking about reusing such glue classes like PostgreSQLArrayJdbcTypeConstructor and OracleXmlArrayJdbcTypeConstructor that you brought up. I'm talking about copying 500+ line classes for no good reason.

Thanks. I got it. I will check these classes. And I remember only AbstractPostgreSQLStructJdbcType. I will check all of them later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants